package com.sctvcloud.zhaohua_sd.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.base.BaseActivity;
import com.sctvcloud.zhaohua_sd.beans.NewsItem;
import com.sctvcloud.zhaohua_sd.ui.activities.TopicDetailActivity;
import com.sctvcloud.zhaohua_sd.ui.utils.GlideUtil;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuxipan on 2017-11-15.
 */

public class TopicDetailSubHolder extends BaseAbsHolder<NewsItem> implements View.OnClickListener {
    public TopicDetailSubHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @BindView(R.id.item_top_detail_sub_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_top_detail_sub_title)
    protected CustomFontTextView title;
//    private TopicItem topicItem;

    @BindView(R.id.item_top_detail_sub_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_top_detail_sub_type)
    protected CustomFontTextView type;

    private NewsItem newsItem;

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewsItem fTopic) {
        this.newsItem = fTopic;
        type.setText("子专题");

        if (!TextUtils.isEmpty(fTopic.getNewsTitle())) {
            title.setText(fTopic.getNewsTitle());
        } else {
            title.setText("");
        }
        if (!TextUtils.isEmpty(fTopic.getPubTime())) {
            DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = format1.parse(fTopic.getPubTime());
                time.setText(format2.format(date));
            } catch (ParseException e) {
                time.setText("");
                e.printStackTrace();
            }

        } else {
            time.setText("");
        }
        //title.setText(TextUtils.isEmpty(fTopic.getTopTitle()) ? context.getString(R.string.default_title) : fTopic.getTopTitle());
        if (!TextUtils.isEmpty(fTopic.getNewsImage())) {
            GlideUtil.getGlideWithLarge169Def(context, fTopic.getNewsImage()).into(img);
            //Glide.with(context).load(fTopic.getTopImage()).into(img);
        }
    }


    @Override
    public void onClick(View v) {
        Intent intent = new Intent(context, TopicDetailActivity.class);
        intent.putExtra(BaseActivity.EX_URL, newsItem.getNewsUrl());
        context.startActivity(intent);
    }
}
